package com.example.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.example.domain.Announcements;
import com.example.service.IAnnouncementsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 通告管理Controller
 * 
 * @author 何曼伶
 * @date 2024-12-11
 */
@RestController
@RequestMapping("/announcements")
public class AnnouncementsController extends BaseController
{
    @Autowired
    private IAnnouncementsService announcementsService;

    /**
     * 查询通告管理列表
     */
    @RequiresPermissions("notice:announcements:list")
    @GetMapping("/list")
    public TableDataInfo list(Announcements announcements)
    {
        startPage();
        List<Announcements> list = announcementsService.selectAnnouncementsList(announcements);
        return getDataTable(list);
    }

    /**
     * 导出通告管理列表
     */
    @RequiresPermissions("notice:announcements:export")
    @Log(title = "通告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Announcements announcements)
    {
        List<Announcements> list = announcementsService.selectAnnouncementsList(announcements);
        ExcelUtil<Announcements> util = new ExcelUtil<Announcements>(Announcements.class);
        util.exportExcel(response, list, "通告管理数据");
    }

    /**
     * 获取通告管理详细信息
     */
    @RequiresPermissions("notice:announcements:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(announcementsService.selectAnnouncementsById(id));
    }

    /**
     * 新增通告管理
     */
    @RequiresPermissions("notice:announcements:add")
    @Log(title = "通告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Announcements announcements)
    {
        return toAjax(announcementsService.insertAnnouncements(announcements));
    }

    /**
     * 修改通告管理
     */
    @RequiresPermissions("notice:announcements:edit")
    @Log(title = "通告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Announcements announcements)
    {
        return toAjax(announcementsService.updateAnnouncements(announcements));
    }

    /**
     * 删除通告管理
     */
    @RequiresPermissions("notice:announcements:remove")
    @Log(title = "通告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(announcementsService.deleteAnnouncementsByIds(ids));
    }
}
